/*
    Copyright 2009 Barnet Wagman

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
 */

package ot;

import java.io.*;

/** A <tt>Serializer</tt> handles the details of converting an object into
 *  the form in which it will be stored and reversing the process.
 *  E.g. {@link GzipSerializer} first serialized an object and then compresses
 *  it.
 *
 * @author Barnet Wagman
 */
public interface Serializer {

        /** Serializes the object to the
         *  specified file. <i><b>Warning</b></i>: if the specified
         *  file exists, it will be overwritten.
         *
         * @param f
         * @param obj
         * @throws ot.OtException
         */
    public void objectToFile(File f, Serializable obj) throws OtException;

        /** Deserializes the object stored in the specified file.
         * 
         * @param f
         * @return
         * @throws ot.OtException if the file does not exist or
         *      an exception occurs during deserialization.
         */
    public Object fileToObject(File f)  throws OtException;

        /** Serializes the object to a byte array.
         * 
         * @param obj
         * @return
         * @throws ot.OtException
         */
    public byte[] objectToByteArray(Serializable obj) throws OtException;

        /** Deserializes an object in a byte array.
         *
         * @param B
         * @return
         * @throws ot.OtException
         */
    public Object byteArrayToObject(byte[] B) throws OtException;

        /** Gets the filename extension used by this <tt>Serializer</tt>.
         *  It's best if each implementation of <tt>Serializer</tt> has
         *  its own, unique filename extension, although this is
         *  not required.
         *
         * @return
         */
    public String getObjectNameExtension();
}
